package com.beehoo.dcportal.admin.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.beehoo.dcportal.admin.dao.CommentDao;
import com.beehoo.dcportal.common.base.BaseDao;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.CommentBean;

public class CommentDaoImpl extends BaseDao implements CommentDao {
	
	private static final Logger logger = Logger.getLogger(CommentDaoImpl.class);

	@Override
	public int auditComment(CommentBean commentBean) throws BaseException {
		int ret = 0;
		try {
			ret = sqlMapClient.update("admin-comment.auditComment", commentBean);
			logger.info("评论管理-审核评论|#[评论状态：" + commentBean.getCommentState()
					+ "],[审核人编号：" + commentBean.getAuditorId()
					+ "],[审核人名称：" + commentBean.getAuditor()
					+ "],[评论编号：" + commentBean.getCommentId()
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("评论管理-审核评论|#[评论状态：" + commentBean.getCommentState()
					+ "],[审核人编号：" + commentBean.getAuditorId()
					+ "],[审核人名称：" + commentBean.getAuditor()
					+ "],[评论编号：" + commentBean.getCommentId()
					+ "],失败!异常：" + e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.comment.audit.error");
		}
		return ret;
	}

	@Override
	public CommentBean queryComment(Map<String, Object> paramMap)
			throws BaseException {
		CommentBean commentBean = null;
		try {
			commentBean = (CommentBean) sqlMapClient.queryForObject(
					"admin-comment.queryCommentDetail", paramMap);
			logger.info("评论管理-评论详细查询|#[中心编号：" + paramMap.get("streetId")
					+ "],[评论编号：" + paramMap.get("commentId")
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("评论管理-评论详细查询|#[中心编号：" + paramMap.get("streetId")
					+ "],[评论编号：" + paramMap.get("commentId")
					+ "],失败!异常：" + e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.comment.query.error");
		}
		return commentBean;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CommentBean> queryComments(Map<String, Object> paramMap)
			throws BaseException {
		List<CommentBean> commentsLs = null;
		try {
			commentsLs = sqlMapClient.queryForList(
					"admin-comment.queryCommentForList", paramMap);
			logger.info("评论管理-评论列表查询|#[中心编号：" + paramMap.get("streetId")
					+ "],[评论编号：" + paramMap.get("commentId")
					+ "],[起始时间：" + paramMap.get("beginDate")
					+ "],[结束时间：" + paramMap.get("endDate")
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("评论管理-评论列表查询|#[中心编号：" + paramMap.get("streetId")
					+ "],[评论编号：" + paramMap.get("commentId")
					+ "],[起始时间：" + paramMap.get("beginDate")
					+ "],[结束时间：" + paramMap.get("endDate")
					+ "],失败!异常：" + e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.comment.query.error");
		}
		return commentsLs;
	}
	

	@Override
	public int queryCommentCount(Map<String, Object> paramMap)
			throws BaseException {
		int ret = 0;
		try {
			ret = (Integer) sqlMapClient.queryForObject("admin-comment.queryCommentCount",
					paramMap);
			logger.info("评论管理-评论列表总数查询|#[中心编号：" + paramMap.get("streetId")
					+ "],[评论编号：" + paramMap.get("commentId")
					+ "],[起始时间：" + paramMap.get("beginDate")
					+ "],[结束时间：" + paramMap.get("endDate")
					+ "],成功!");
		} catch (SQLException e) {
			logger.error("评论管理-评论列表总数查询|#[中心编号：" + paramMap.get("streetId")
					+ "],[评论编号：" + paramMap.get("commentId")
					+ "],[起始时间：" + paramMap.get("beginDate")
					+ "],[结束时间：" + paramMap.get("endDate")
					+ "],失败!异常：" + e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.comment.query.error");
		}
		return ret;
	}

	@Override
	public int delComment(String commentId) throws BaseException {
		int ret = 0;
		try {
			ret = sqlMapClient.delete("admin-comment.delComment", commentId);
			logger.info("评论管理-删除评论|#[评论编号： " + commentId + "成功!");
		} catch (SQLException e) {
			logger.error("评论管理-删除评论|#[评论编号： " + commentId + "失败!异常："
					+ e.getMessage());
			throw new BaseException(e, "custom.messages.error.comment.del.error");
		}
		return ret;
	}

}
